// 定义扫码参数类型
interface ScanOptions {
	success ?: (res : any) => void
	onlyFromCamera ?: boolean
	scanType ?: Array<'barCode' | 'qrCode'>
}

function mPageSacnPopup() {
	return {
		openScan(param : ScanOptions = {}) {
			console.log(uni.getStorageSync('sysDeviceInfo'));
			let scanDeviceType = null;
			// 获取设备类型
			if (uni.getStorageSync('sysDeviceInfo')) {
				scanDeviceType = JSON.parse(uni.getStorageSync('sysDeviceInfo'))?.scanDeviceType || null;
			}

			switch (scanDeviceType) {
				case 'GKJ': // 工控机
					uni.navigateTo({
						url: "/commonPage/Tool/pageScanByGKJ",
						events: {
							success: function (res : any) {
								param.success && param.success(res)
								uni.hideKeyboard()
							}
						}
					})
					break

				default:
					// 普通扫码
					uni.scanCode({
						onlyFromCamera: param.onlyFromCamera ?? true,
						scanType: param.scanType ?? ['qrCode'],
						success: function (res) {
							param.success && param.success(res)
							uni.hideKeyboard()
						},
						complete: () => {
						}
					})
					break
			}
		}
	}
}

export default mPageSacnPopup();
// export default { mPageSacnPopup }